package com.java.system.controller;

import com.java.system.entity.Result;
import com.java.system.entity.User;
import com.java.system.service.ILoginService;
import com.java.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  用户控制器
 * </p>
 *
 * @author xiaoman
 * @since 2023-07-11
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/hello")
    public Result hello(){
        return Result.success("Hello");
    }
    @Autowired
    IUserService userService;
    @GetMapping("/list")
    public Result getAllUser(){
        List<User> userList = userService.select();
        Result result=Result.success();
        result.put("data",userList);
        return result;
    }

    @PostMapping("/add")
    public Result insertUser(@RequestBody User user){
        userService.insertUser(user);
        return Result.success("增加用户成功");
    }
    @GetMapping("/{id}")
    public Result getUserById(@PathVariable("id") Integer id){
        User user = userService.selectUserById(id);
        Result result=Result.success();
        result.put("data",user);
        return  result;
    }
    @PutMapping()
    public Result updateUser(@RequestBody User user){
        userService.updateUser(user);
        return Result.success("修改用户成功");
    }

    @DeleteMapping("/{id}")
    public Result deleteUser(@PathVariable("id")Integer id){
        userService.deleteUser(id);
        return Result.success("删除用户成功");
    }


}
